package utils.math_utils;

import java.util.HashSet;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;

public class Coordinate {

	private final int [] coordinate;
	
	public Coordinate (int [] coordinate) {
		this.coordinate = coordinate;
	}
	
	public Coordinate(short [] coordinate) {
		this.coordinate = new int[3];
		this.coordinate[0]  = coordinate[0];
		this.coordinate[1]  = coordinate[1];
		this.coordinate[2]  = coordinate[2];
	}
	
	public Coordinate (int x, int y, int z) {
		int [] co = {x, y, z};
		coordinate = co;
	}

	 public boolean equals(Object obj) {
		   if (obj == null) { return false; }
		   if (obj == this) { return true; }
		   if (obj.getClass() != getClass()) {
		     return false;
		   }
		   Coordinate co = (Coordinate) obj;
		   return new EqualsBuilder().append(coordinate[0],
				   co.getCoordinate()[0]).
				   append(coordinate[1], co.getCoordinate()[1]).
				   append(coordinate[2], co.getCoordinate()[2]).isEquals();		   
	 }
	
	public int hashCode(){
		return new HashCodeBuilder(61, 107).append(coordinate[0]).
				append(coordinate[1]).
				append(coordinate[2]).
				toHashCode();	
	}
	
	public int [] getCoordinate () {
		return coordinate;
	}
	
	public int getX(){
		return coordinate[0];
	}
	
	public int getY(){
		return coordinate[1];
	}
	
	public int getZ() {
		return coordinate[2];
	}
	
	public static void main(String [] args) {
		
		Coordinate c1 = new Coordinate(1, 2, 3);
		Coordinate c2 = new Coordinate(1, 2, 3);
		
		HashSet<Coordinate> bob = new HashSet<Coordinate>();
		bob.add(c1);
		
		System.out.println("Equals: " + c1.equals(c2) + " " + c2.equals(c1));
		System.out.println("Equals ==: " + (c1 == c2));
		System.out.println("Contains: " + bob.contains(c2));
		
	}
	
}

